﻿/* 
 * File:   dig_encode.h
 * Author: aple
 */

#ifndef __dig_ENCODE_H_H_
#define	__dig_ENCODE_H_H_

#include "stdint.h"

#ifdef	__cplusplus
extern "C" {
#endif

	/*--------------------------------------------------------------------*
	*半双工单线通信
	*高位在前
	*为简化编码，最高位数据必须为0
	*IO必须为开漏或弱上拉输出
	*发送间隔至少上次数据尾部32个时钟
	*接收间隔至少16时钟，发送结束后可立即接收
	*---------------------------------------------------------------------*/

	typedef struct
	{
		uint8_t sample_time_cnt;
		uint8_t idle_time_cnt;

		int8_t in_flt;
		int8_t in_st;

		uint8_t bit_cnt;
		uint8_t bit_sv;
		uint8_t b_rx_ne;

		uint8_t snd_st;
		uint8_t rcv_st;

		uint8_t rcv_allow;
		uint8_t tx_allow;

		uint32_t rx_shift;
		uint32_t rx;
		uint32_t tx;

		void(*tx_out)(uint8_t st);
		uint8_t(*rx_in)(void);
		void(*io_dir)(uint8_t dir); //0r1w
	} dig_encode_type;

	void dig_encode_handle(dig_encode_type *obj);
	uint32_t dig_encode_read(dig_encode_type *obj);
	void dig_encode_write(dig_encode_type *obj, uint32_t dat);



#ifdef	__cplusplus
}
#endif

#endif	/* __dig_ENCODE_H_H_ */

